package com.bbzn.user.client.handle;
import com.alibaba.fastjson.JSONObject;
import com.bbzn.user.client.vo.ResultVO;
import com.bbzn.user.client.enums.ResultCode;
import com.bbzn.user.client.exception.ApiException;
import com.bbzn.user.client.exception.DefinitException;
import com.bbzn.user.client.utils.BaseResponse;
import io.jsonwebtoken.JwtException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @Author wulongbo
 * @Date 2021/10/27 12:00
 * @Version 1.0
 * 全局异常控制类
 */
@RestControllerAdvice
public class ExceptionControllerAdvice {


    @ExceptionHandler(DefinitException.class)
    public BaseResponse<JSONObject> handleDefinitException(DefinitException e) {
        // 注意哦，这里返回类型是自定义响应体
        return new BaseResponse<JSONObject>(e.getCode(),e.getMsg());
    }

    @ExceptionHandler(ApiException.class)
    public ResultVO<String> handleApiException(ApiException e) {
        // 注意哦，这里返回类型是自定义响应体
        return new ResultVO<>(ResultCode.FAILED, e.getMsg());
    }


    @ExceptionHandler(JwtException.class)
    public  ResultVO<String> handleJwtException(JwtException e) {
        return new ResultVO<>(ResultCode.SAFETY_INVALID);
    }
}
